#include<iostream>
#include<string>
using namespace std;
const int N = 1e3 + 10;
int n;
string a[N];
int b[N], c[N];
int main()
{
    cin >> n;
    
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    int m; cin >> m;
    for (int i = 1; i <= m; i++)
    {
        int x; cin >> x;
        for (int j = 1; j <= n; j++)
        {
            if (b[j] == x)
            {
                cout << a[j] << " " << c[j] << endl;
                break;
            }
        }
    }
    return 0;
}